Imports System.Diagnostics
Imports System.Reflection
Imports System.Text.RegularExpressions
Imports System.Resources

''' <summary>
''' Email address
''' </summary>
''' <remarks></remarks>
Public Structure EmailAddress

  Private _address As String
  Private _name As String

  ''' <summary>
  ''' Address
  ''' </summary>
  ''' <value></value>
  ''' <returns></returns>
  ''' <remarks></remarks>
  Public Property Address() As String
    Get
      Return _address
    End Get
    Set(ByVal value As String)
      _address = value
    End Set
  End Property

  ''' <summary>
  ''' Contact's name.
  ''' </summary>
  ''' <value></value>
  ''' <returns></returns>
  ''' <remarks></remarks>
  Public Property Name() As String
    Get
      Return _name
    End Get
    Set(ByVal value As String)
      _name = value
    End Set
  End Property

  ''' <summary>
  ''' Determins if email address is valid.
  ''' </summary>
  ''' <returns></returns>
  ''' <remarks></remarks>
  Public Function IsAddressValid() As Boolean
    Return ValidationHelper.IsValidEmail(Me.Address)
  End Function

  ''' <summary>
  ''' Determins if contact name is valid.
  ''' </summary>
  ''' <returns></returns>
  ''' <remarks></remarks>
  Public Function IsNameValid() As Boolean
    Return ValidationHelper.IsValidString(Me.Name)
  End Function

  ''' <summary>
  ''' Combines contact name and email address for use in sending email.
  ''' </summary>
  ''' <param name="name">Contact name</param>
  ''' <param name="address">Contact email address</param>
  ''' <returns>Combined address as <see cref="String"></see></returns>
  ''' <remarks></remarks>
  Public Shared Function CombineNameAddress(ByVal name As String, ByVal address As String) As String
    Return String.Format(CultureInfo.CurrentCulture, "{0} <{1}>", name, address)
  End Function

  ''' <summary>
  ''' Creates object.
  ''' </summary>
  ''' <param name="address">Sets email address</param>
  ''' <remarks></remarks>
  Public Sub New(ByVal address As String)
    Me.Address = address
  End Sub

  ''' <summary>
  ''' Creates object.
  ''' </summary>
  ''' <param name="address">Sets email address</param>
  ''' <param name="name">Sets conacts name</param>
  ''' <remarks></remarks>
  Public Sub New(ByVal address As String, ByVal name As String)
    Me.Address = address
    Me.Name = name
  End Sub

End Structure


''' <summary>
''' General helper functions.
''' </summary>
Public NotInheritable Class General

  ''' <summary>
  ''' Writes to event log.
  ''' </summary>
  ''' <param name="message">The message to write.</param>
  ''' <param name="type">The event type.</param>
  Public Shared Sub WriteToEventLog(ByVal message As String, ByVal type As EventLogEntryType)

    EventLog.WriteEntry(My.Application.Info.Title.ToString(), message, type)

  End Sub

  ''' <summary>
  ''' Modified IIf fuction that works properly!
  ''' </summary>
  ''' <typeparam name="T">Type to return.</typeparam>
  ''' <param name="expression">if set to <c>true</c> [expression].</param>
  ''' <param name="truePart">The true part.</param>
  ''' <param name="falsePart">The false part.</param>
  ''' <returns>Defined type.</returns>
  Public Shared Function IIf(Of T)(ByVal expression As Boolean, ByVal truePart As T, ByVal falsePart As T) As T
    If expression Then
      Return truePart
    Else
      Return falsePart
    End If
  End Function

  Private Sub New()
  End Sub

End Class
